﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%@Import Namespace="Heritage.Codebox" %>
<script type="text/javascript">
    function blurUserName() {
        var elem = document.getElementsByName('username')[0];
        if (elem.value.length == 0) 
        {
            elem.style.color = "Gray";
            elem.value = "Имя пользователя";
        }
    }
    function grayUserName() {
        var elem = document.getElementsByName('username')[0];
        elem.style.color = "Gray";
        elem.value = "Имя пользователя";
    }
    function grayPassword() {
        var elem = document.getElementsByName('password')[0];
        elem.style.display = "none";
        elem = document.getElementsByName('fakepass')[0];
        elem.style.color = "Gray";
        elem.style.display = "";
        elem.value = "Пароль";
    }
    function blurPassword() {
        var elem = document.getElementsByName('password')[0];
        if (elem.value.length == 0) {
            elem.style.display = "none";
            elem = document.getElementsByName('fakepass')[0];
            elem.style.color = "Gray";
            elem.style.display = "";
            elem.value = "Пароль";
        }
    }
    function focusUserName() {
        var elem = document.getElementsByName('username')[0];
        if (elem.style.color == "Gray" || elem.style.color == "gray") {
            elem.value = "";
        }
        elem.style.color = "Black";
    }
    function focusPassword() {
        var elem = document.getElementsByName('fakepass')[0];
        elem.style.display = "none";
        var elem2 = document.getElementsByName('password')[0];
        elem2.style.display = "";
        elem2.style.cursor = "text";
        elem2.focus();
    }
    function checkData() {
        var elem = document.getElementsByName('username')[0];
        if (elem.style.color == "Gray" || elem.style.color == "gray") {
            elem.value = "";
        }
    }
</script>
<%  string model = ViewData.Model as string;
    if (Utils.IsAccessAllowed()) { %>
            <div id="leftmenu" style="<%=model %>">
            <% 
                string style = "";
                if (!Utils.IsAuthenticated())
               {
                   style = " border-top: 1px; border-top-style:outset; border-top-color: #6B562D;";
                    %>
                <form action="/Auth/SignIn" method=post name="signin">
                <input type="text" name="username" onfocus="focusUserName();" onblur="blurUserName();" style="margin-left: 20px; margin-bottom:4px; margin-top: 20px; width:125px; height:16px; font-size:14px;"/><br />
                <input type="text" name="fakepass" onfocus="focusPassword();" id="pass0" style="margin-left: 20px; margin-bottom:4px; width:125px; height:16px; font-size:14px;"/>
                <input type="password" name="password" onfocus="focusPassword();" onblur="blurPassword();" id="pass1" style="display:none; margin-left: 20px; margin-bottom:4px; width:125px; height:16px; font-size:14px;"/><br />
                <a href="#" class="awesome" onclick="document.signin.submit();" style="margin-left:20px;">Войти</a>
                <!--<div class="button20" style="padding-left:20px; padding-top:2px;" onclick="document.signin.submit();">
                    <div class="l"></div>
                    <div class="m">Войти</div>
                    <div class="r"></div>
                </div>-->
                </form>                              
                <div style="padding-top:24px; padding-left:20px; padding-bottom:20px; font-size:10px;">
                <a href="/Auth/LostPassword">Забыли пароль?</a>
                </div>
                <% } %>
                <ul style="padding-top:6px; padding-left:20px;<%=style%>" class="FreeSet">
                <% if (!Utils.IsAuthenticated())
                   { %>
                    <li><a href="/">На главную</a></li>
                    <li><a href="/Auth/Register">Регистрация</a></li>
                    <% }
                   else
                   {
                       if (Utils.IsUserValidated())
                       { %>
                        <li><a href="/Home/Personal">Моя страница</a></li>
                        <li><a href="/Home/JoinGame">Запись в игру</a></li>
                        <li><a href="/Home/ActiveGames">Текущие игры</a></li>
                        <li><a href="/Home/AllMyGames">Все ваши игры</a></li>
                        <%--<li><a href="/Home/Statistics">Статистика</a></li>--%>
                        <li><span style="color:#D1BA8F; font-size:18px;">Статистика</span></li>
                        <% if (Utils.GetCurrentUser().UserRole >= Constants.USER_ROLE_SENIOR)
                           { %>
<%--                            <li><a href="/Home/StartGame">Запуск новой партии</a></li>
--%>
                        <li><span style="color:#D1BA8F; font-size:18px;">Запуск партии</span></li>

                        <% } %>
                        <% if (Utils.IsGameMasterAndAbove())
                           { %>
                            <li><a href="/GameMaster/Cities">Игровые города</a></li>

                        <% } %>
                        <% if (Utils.IsAdmin())
                           { %>
                            <li><a href="/Admin/Logs">Просмотр логов</a></li>

                        <% } %>
                       <% } %>
                        <li><a href="/Game/MyCodes">Приглашения</a></li>
                    <% } %>
                    <li><a href="/Auth/Rules">Правила</a></li>
                    <li><a href="/Auth/About">О проекте</a></li>
                <% if (Utils.IsAuthenticated())
                   { %>
                    <li><a href="/Auth/SignOut">Выход</a></li>
                    <% } %>
                </ul> 

                <% if (Utils.IsAuthenticated() && Utils.IsUserValidated())
                   {
                       %>
                <div class="infoheader" style="margin-top: 16px;">Страницы игроков</div>
                <div class="nodecor">
		        <fieldset style="padding-bottom:0px; margin-bottom:0px;">
			        <select name="speedC" id="speedC" style="text-decoration:none; margin-bottom:0px; padding-bottom:0px; color:#6B562C !important;" onchange="window.location='/Home/Personal/'+this.value;">
                    <%=Utils.CreatePlayerOptionList(Session["CurrentGuid"] as string) %>
			        </select>
		        </fieldset>
                </div>              


                       <%
                       List<Heritage.Games> games = Utils.GetMyActiveGames();
                       if (games.Count > 0)
                       { %>
                       <div class="infoheader" style="margin-top:18px;">Мои текущие игры</div>
                       <div class="leftgamelist">
                       <% foreach (Heritage.Games g in games)
                          { 
                              string info = "";
                              if (g.GameState == Constants.GAME_STATE_AVAILABLE)
                              {
                                  info = string.Format("{0}/{1}", Utils.GetPlayersCount(g.GameName), g.Players);
                              }
                              else if (g.GameState == Constants.GAME_STATE_IN_PROGRESS)
                              {
                                  info = string.Format("день {0}", g.GameTurn);
                              }
                              else if (g.GameState == Constants.GAME_STATE_STOPPED)
                              {
                                  info = string.Format("остановлена");
                              }
                              else if (g.GameState == Constants.GAME_STATE_FINISHED)
                              {
                                  info = string.Format("завершена");
                              } 

                              %>
                          <a href="/Game/View/<%=g.GameName %>"><%=g.GameName %> (<%=info %>)</a><br />
                       <% } %>
                       </div>
                       <%}
                       List<Heritage.Users>  hb = Utils.GetTodayCelebrations();
                       if (hb.Count > 0)
                       {%>
                       <div class="infoheader" style="margin-top:18px;">С днем рождения!</div>
                       <div class="leftgamelist">
                       <% foreach (var u in hb)
                        { %>
                          <a href="/Home/Personal/<%=u.ID.ToString("N") %>"><%=u.Username %> (<%=Utils.GetUserYears(u.ID) %>)</a><br />                            
                        <% } %>
                       </div>
                       <%
                       }
                   } %>
            </div>
            <script type="text/javascript">
            try {
                grayUserName();
                grayPassword();
            }
            catch (e) {
            }
            </script>
            <% } %>